<!-- index页面信息 -->

<template>
  <div class="home_contain">
    <!-- 模块区域 -->
    <div class="mywork_contain">
      <!-- 模块标题 -->
      <div class="mywork_title">
        <span>我的工作</span>
        <!-- <i class="iconfont icon-wenbenshuru" @click="eidtworkName"></i> -->
      </div>

      <div class="big_box">
        <!-- v-for 遍历盒子 -->
        <!-- 模块中的每一个功能区盒子 -->
        <div class="small_box">
          <div class="Icon_title">
            <span>常用功能</span>
            <i
              class="iconfont icon-wenbenshuru"
              :style="isShowEdit ? 'color:red' : ''"
              @click="isShowEdit = !isShowEdit"
            ></i>
          </div>
          <div class="Icon_box">
            <!-- v-for 遍历快捷图标 -->
            <!-- 快捷功能模块 -->
            <div
              class="Icon_box_item"
              v-for="item in menuCount"
              :key="item.id"
              @click="menuItemClick(item)"
            >
              <div class="tubiao">
                <!-- <img src="../../src/assets/img/gongneng.png" alt /> -->
                <img src="../../src/assets/img/arrow.png" alt />
              </div>
              <div class="IconTitle">{{ item.name }}</div>
              <div
                class="iconfont icon-jianshao"
                :style="
                isShowEdit ? 'display: inline-block;' : 'display: none;'
              "
                @click.stop="cancelShouCang(item)"
              ></div>
            </div>
            <!-- 添加按钮 -->
            <div class="Icon_box_item">
              <div class="iconfont icon-zengjia" @click="addIconBoxItem"></div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      menuCount: "",
      mainMenuVisble: false, // 弹窗菜单的显示与隐藏
      isShowEdit: false,
      kanbanVisble: false, // n看板的显示于隐藏
      kanbanVisble1: false,
      maxHeight: "250",

      isActiveBtn: "",
      // 生产看板
      productionName: "",
      editUrl: "",
      openType: "", //打开页面的类型
      dataItems: [],
      orderDataItems: [], // 单据数据
      totalItems: [], // 汇总状态

      // 工序看板
      dataProcedureItems: [],
      orderProcedureDataItems: [],
      totalProcedureItems: []
    };
  },
  components: {
  },
  created() {
    this.getMenuList(); //获取常用功能
  },
  methods: {
    //获取常用功能
    async getMenuList() {
      let orgId = JSON.parse(sessionStorage.getItem("orgData")).orgType;
      // console.log(orgId);
      let { data: res } = await this.$http.get("/api/collectList", {
        params: {
          orgId
        }
      });
      console.log(res);
      if (res.result) {
        this.menuCount = res.list;
      }
    },

    // 获取【生产日历看板】数据
    async getProductDate(date) {
      let orgId = JSON.parse(sessionStorage.getItem("orgData")).orgType;
      let month =
        date.getMonth() + 1 < 10
          ? "0" + (date.getMonth() + 1).toString()
          : (date.getMonth() + 1).toString();
      let { data: res } = await this.$http.get("/api/boardProductionOrder", {
        params: {
          date: date.getFullYear() + "-" + month,
          orgId
        }
      });
      console.log(date.getFullYear() + "-" + month);

      console.log(res);
      if (res.result) {
        this.dataItems = res.data.dataItems;
        this.orderDataItems = res.data.orderDataItems;
        this.totalItems = res.data.totalItems;
      } else {
        this.$message.error(res.msg);
      }
    },

    // 获取【工序日历看板】
    async getProcedureDate(date) {
      let orgId = JSON.parse(sessionStorage.getItem("orgData")).orgType;
      let month =
        date.getMonth() + 1 < 10
          ? "0" + (date.getMonth() + 1).toString()
          : (date.getMonth() + 1).toString();
      let { data: res } = await this.$http.get("/api/boardCraftOrder", {
        params: {
          date: date.getFullYear() + "-" + month,
          orgId
        }
      });
      console.log(res);
      if (res.result) {
        this.dataProcedureItems = res.data.dataItems;
        this.orderProcedureDataItems = res.data.orderDataItems;
        this.totalProcedureItems = res.data.totalItems;
      } else {
        this.$message.error(res.msg);
      }
    },

    // 监听添加按钮的点击
    addIconBoxItem() {
      this.mainMenuVisble = true;
    },
    // 监听【我的工作】标题的点击
    eidtworkName($event) {
      console.log($event);
    },

    // 监听对话框的关闭点击
    MeunVisClose() {
      this.mainMenuVisble = false;
    },

    // 监听对话框里返回的点击事件
    shoucangClick() {
      this.getMenuList();
      // this.MeunVisClose();
    },

    // 编辑【取消收藏】图标的点击事件
    async cancelShouCang(item) {
      // console.log(item);
      let orgId = JSON.parse(sessionStorage.getItem("orgData"));
      // item1.isShowIcon = !item1.isShowIcon;
      let { data: res } = await this.$http.get("/api/addMenuCollect", {
        params: {
          key: item.key,
          orgId: orgId.orgType
        }
      });
      if (res.result) {
        this.$message({
          message: res.msg,
          type: "success"
        });
        // this.isShowEdit = !this.isShowEdit;
        this.getMenuList();
      } else {
        this.$message({
          message: res.msg,
          type: "error"
        });
      }
    },

    // 点击【功能菜单】触发事件
    menuItemClick(path) {
      console.log(path);
      // 避免地址重构,对数据进行互换一下。
      this.$store.commit("eidtActionPath", JSON.parse(JSON.stringify(path)));
      // let i = this.$store.getters.tabPathListFindIndex(item1);   //【不可重复打开的相同界面的方法】
      // if (i == -1) {
      // console.log(i);
      // tab中不存在该目录信息
      this.$store.commit("pushTabPathList", this.$store.state.activePath);
      // }
    },

    // 看板情况按钮
    isShowVisble(item) {
      this.kanbanVisble = true;
      this.isActiveBtn = item.title;
    },
    isShowVisble1(item) {
      this.kanbanVisble1 = true;
      this.isActiveBtn = item.title;
    },
    kanbanVisClose() {
      this.kanbanVisble = false;
    },
    kanbanVisClose1() {
      this.kanbanVisble1 = false;
    },
    // 监听看板列表的数据点击事件（双击事件）
    toModule(item) {
      alert(item);
    },
    // 单据模块的点击事件
    tabClick(tab) {
      // console.log(tab);
      // console.log(tab.$attrs.openType);
      this.productionName = tab.label; // 页面标题
      this.openType = tab.$attrs.openType; // 打开的页面类型
      // console.log(this.editUrl);
    },
    // 看板的双击行 事件
    rowDblclick(row) {
      let params = {
        openType: this.openType, //用于打开页面
        rowId: row.id,
        // 去除“未处里数据的俩字”
        name:
          this.productionName
            .split("(未处理)")
            .slice()
            .join("")
            .split(" ")
            .slice(0, 1) +
          "-" +
          "编辑",
        url: this.editUrl
      };
      this.$store.commit("eidtActionPath", JSON.parse(JSON.stringify(params)));
      this.$store.commit("pushTabPathList", this.$store.state.activePath);
      this.kanbanVisble = false;
      this.kanbanVisble1 = false;
    }
  },
  watch: {
    // 刷新请求【常用功能】
    "$store.state.activePath": function() {
      if (this.$store.state.activePath == this.$store.state.tabPathList[0]) {
        this.getMenuList();
      }
    }
  }
};
</script>
<style scoped>
.home_contain {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: auto;
  background-color: #e8ecf6;
}

.mywork_contain {
  width: 100%;
  padding: 20px;
  box-sizing: border-box;
}

.mywork_title {
  height: 20px;
  margin-bottom: 10px;
  padding-left: 10px;
  display: flex;
  align-self: center;
  border-left: 4px solid blue;
}

.mywork_title > span {
  font-weight: 700;
}

/* 编辑图标的样式 */
.icon-wenbenshuru {
  display: none;
}

.mywork_title:hover .icon-wenbenshuru,
.Icon_title .icon-wenbenshuru {
  display: inline-block;
  font-size: 18px;
  padding-top: 3px;
  padding-left: 10px;
  color: #aaa;
}

.big_box {
  width: 100%;
  height: 450px;
  display: flex;
  box-sizing: border-box;
}

.small_box {
  /* width: 370px; */
  width: 100%;
  height: 100%;
  padding: 10px 20px;
  color: #333333;
  box-sizing: border-box;
  border-radius: 10px;
  background-color: #ffffff;
  margin-right: 20px;
}

.Icon_title {
  height: 30px;
  display: flex;
  font-weight: 700;
}

.Icon_box {
  width: 100%;
  height: calc(100% - 30px);
  display: flex;
  flex-wrap: wrap;
  overflow: auto;
  align-content: flex-start;
}

.Icon_box_item {
  width: 90px;
  height: 100px;
  margin: 10px 15px;
  box-sizing: border-box;
  /* border: 1px solid #333333; */
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  position: relative;
  background-color: #fff;
  /* border-radius: 10px; */
  /* box-shadow: 0px 0px 5px #a79393; */
}

.tubiao {
  width: 60px;
  height: 60px;
  padding: 5px;
  box-sizing: border-box;
  border-radius: 10px;
  font-size: 40px;
  /* color: #460de2; */
  text-align: center;
  line-height: 60px;
  /* background-color: #44cdc5; */
}

.tubiao img {
  width: 100%;
  height: 100%;
}

.IconTitle {
  width: 100%;
  height: 40px;
  font-size: 14px;
  color: #6d6d6d;
  text-align: center;
}

.icon-jianshao {
  position: absolute;
  top: -3px;
  right: 8px;
  font-size: 20px;
  color: red;
}

.icon-zengjia {
  font-size: 50px;
  margin-bottom: 20px;
  color: #bbb;
  background-color: #ffffff;
  border-radius: 5px;
  border: 2px solid #dddd;
}

/* 增加主控制台的对话框 */
.addMenu {
  display: flex;
  overflow: auto;
}

.mainbox {
  height: 400px;
  overflow: auto;
}

.listClass {
  width: 100%;
  height: 35px;
  /* border-bottom: 1px solid #000; */
  font-size: 16px;
  display: flex;
  align-items: center;
  box-sizing: border-box;
}

.listClass div {
  height: 100%;
  flex: 1;
  padding: 0 10px;
  display: flex;
  align-items: center;
  border-right: 1px solid #bbb;
  box-sizing: border-box;
}

.listClass div:last-child {
  border: none;
}

.listClass:first-child {
  border-top: 1px solid #e6edf2;
}

.listClass:nth-child(odd) {
  background-color: #e6edf2;
  border-bottom: 1px solid #e6edf2;
}

.listClass:nth-child(even) {
  background-color: #cfdde7;
  border-bottom: 1px solid #cfdde7;
}

.listClass:hover {
  background-color: #fff;
}
</style>